package creator.prototype.deep;


import lombok.Data;

import java.io.*;

/**
 * 枪兵
 */
@Data
public class DeepGunner implements Serializable {

    /**
     * 编号
     */
    private String indexNo;

    /**
     * 介绍
     */
    private String introduce;

    /**
     * 基础数值
     */
    private DeepNumerical numerical;





    public Object deepClone() { //深拷贝
        //创建流对象
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        ByteArrayInputStream bis = null;
        ObjectInputStream ois = null;

        try {
            //序列化
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(this); //当前这个对象以对象流的方式输出

            //反序列化
            bis = new ByteArrayInputStream(bos.toByteArray());
            ois = new ObjectInputStream(bis);
            DeepGunner sheep = (DeepGunner) ois.readObject();

            return sheep;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            //关闭流
            try {
                bos.close();
                oos.close();
                bis.close();
                ois.close();
            } catch (Exception e2) {
                System.out.println(e2.getMessage());
            }
        }
    }

}
